<?
session_start();
include('conn.php');
$custid = $_SESSION['custid'];
$bid = $_SESSION['bid'];
$fromdt=$_SESSION['fromdt'];
$todt=$_SESSION['todt'];
$subid=$_SESSION['subid'];

$date=$_SESSION['todt'];
$day= substr($date,0,2);
$month = substr($date,3,2);
$year = substr($date,6,4);
$todt=$year.'-'.$month.'-'.$day;

$date=$_SESSION['fromdt'];
$day= substr($date,0,2);
$month = substr($date,3,2);
$year = substr($date,6,4);
$fromdt=$year.'-'.$month.'-'.$day;

$qry1 = "SELECT A.trnid, A.trndate, B.bdesc, C.catdesc, D.custdesc, D.custtype, E.subname, V.custdesc AS vendor, A.debitamt, A.creditamt, A.netrate, A.idnumber,F.bankname, A.branchname, A.remarks, A.paydate, A.enteredby, A.status, G.pdesc
FROM transactionmast A
LEFT JOIN businessmast B ON A.bid = B.bid
LEFT JOIN categorymast C ON A.catid = C.catid
LEFT JOIN customermast D ON A.custid = D.custid
LEFT JOIN subdealermast E ON A.subid = E.subid
LEFT JOIN bankmast F ON A.bankid = F.bankid
LEFT JOIN paymentmast G ON A.payid = G.payid
LEFT JOIN customermast V ON A.venid = V.custid where  
V.custtype = 'Vendor'  and A.status = 0 and
A.trndate >='".$fromdt."' and A.trndate <='".$todt."'";// order by A.trnid desc";
if ($custid >0)
{
    $qry1 =$qry1." and A.custid='".$custid."'";

}
if ($bid >0)
{
	$qry1 =$qry1." and A.bid='".$bid."'";

}
if ($subid >0)
{
	$qry1 =$qry1." and A.subid='".$subid."'";

}

$qry1 =$qry1."order by A.trnid desc";
//echo $qry1 ;
$qry = mysql_query($qry1);
$data = array();
while($rows = mysql_fetch_array($qry))
{
	$date = $rows['trndate'];
	$year= substr($date,0,4);
	$month = substr($date,5,2);
	$day = substr($date,8,2);
//	echo $day.'-'.$month.'-'.$year;
	$date = $day.'-'.$month.'-'.$year;
	$data[] = array("Referenceno" => $rows['trnid'],
				  "Date" => $date, //$rows['trndate'],
				  "Dist_Name" => $rows['custdesc'],
				  "custtype" => $rows['custtype'],
				  "Business" => $rows['bdesc'],
				  "Sub_Category" => $rows['catdesc'],
				  "Sub_delear" => $rows['subname'],
				  "Dr_Amount" => $rows['debitamt'],
				  "Cr_Amount" => $rows['creditamt'],
				  "vendor" => $rows['vendor'],
				  "PNR_Number" => $rows['idnumber'],
				  "netrate" => $rows['netrate'],
				  "Bank" => $rows['bankname'],
				  "Branch" => $rows['branchname'],
                  "payid" => $rows['pdesc'],
                  "paydate" => $rows['paydate'],
                  "remarks" => $rows['remarks'],
                  "enteredby" => $rows['enteredby'],
                  "status" => $rows['status']);
}
echo json_encode($data);

?>